﻿#include "../HDCDomeVideoContainer.h"
#include "../HDCDomeVideoGroup.h"
#include "../../include/HGlobalVariable.h"
#include "../../include/StdAfx.h"
#include "../../include/HSystemInfo.h"
#include "../HCustomWidgets/HComponent.h"
#include "../../include/HSettingConfigOperator.h"


HDCDomeVideoContainer::HDCDomeVideoContainer(QWidget *parent)
    :QWidget(parent)
{
    m_nCPUValue = 0;
    m_fMemeryValue = 0.0;
    m_strCPUAndMemery = QString::fromLocal8Bit("CPU:%1%  内存:%2%").arg(m_nCPUValue).arg(m_fMemeryValue);
    m_pTimer = new QTimer();
    m_pTimer->setInterval(1000);
    connect(m_pTimer,SIGNAL(timeout()),this,SLOT(sltUpdateRealTimeData()));

    initUI();
	//initOpenVideo();
    m_pTimer->start();
	m_bShowFullScreen = false;

	m_iPageCount = 1;
	m_nCurrentVideoGroupIndex = 0;
	m_nCurrentPanelOrder = 0;
	m_nOldVideoCount = 0;
	m_bIsPageChanged = false;
	//m_mapVideoPanelConfig.clear();
	m_nVideoPanelPosTemp = 0;

	m_pTourPlayTimer = new QTimer();
}

HDCDomeVideoContainer::~HDCDomeVideoContainer()
{

}

HDCDomeVideoPanel*  HDCDomeVideoContainer::currentVideoPanel()
{
	////获取当前堆栈窗口的m_pwndVideoGroup，再返回m_pwndVideoGroup的currentVideoPanel
	int nCurrentVideoCount = m_pwndVideoGroup->getCurrentVideoCount();
	//if (!m_pwndVideoGroup->isVideoPanelChecked())
	//{
	//	/*//没有定位焦点时，打开顺序，双击树节点，依次排开
	//	if (nCurrentVideoCount == 1)
	//	{
	//		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->currentWidget());
	//		m_pwndVideoGroup->setPanelChecked(0,false);
	//		return m_pwndVideoGroup->currentVideoPanel();
	//	}
	//	else
	//	{
	//		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->currentWidget());
	//		m_pwndVideoGroup->setPanelChecked(0,false);
	//		m_pwndVideoGroup->setCurrentVideoPanel(m_nCurrentPanelOrder);
	//		m_nCurrentPanelOrder++;
	//		return m_pwndVideoGroup->currentVideoPanel();
	//	}*/
	//	QMessageBox::warning(this,QString::fromLocal8Bit("提示信息！"),QString::fromLocal8Bit("请先选择窗口焦点，再双击树节点打开设备"));
	//	return NULL;
	//}
	//else
	//{
		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->currentWidget());
		QList<HDCDomeVideoPanel*> lstAllVideoPanels = m_pwndVideoGroup->getAllVideoPanels();

		int nPages,nPageIndex,nVideoCount,nBitSteam;
		QString strDeviceId,strKey,strValue,strVideoName,strResolution;
		for(int nVideoPanel = 0; nVideoPanel < lstAllVideoPanels.count(); nVideoPanel++)
		{
			//定位选中的焦点窗口
			//if ( lstAllVideoPanels.at(nVideoPanel)->isVideoPanelChecked() )
			//{
				 return m_pwndVideoGroup->currentVideoPanel();
			//}
		}
	//}
	
}

void HDCDomeVideoContainer::setCurrentVideoGroupIndex(int nIndex)
{
	m_nCurrentVideoGroupIndex = nIndex;
}

//void HDCDomeVideoContainer::setCurrentPageVideoPanel(HDCDomeVideoPanel *videoPanel)
//{
//	m_pwndVideoGroup->setCurrentPageVideoPanels(videoPanel);
//}

int HDCDomeVideoContainer::getStackLayoutWidgetPageCount()
{
	return m_pslAddVideoPage->count();
}

int HDCDomeVideoContainer::getCurrentVideoGroupIndex()
{
	return m_nCurrentVideoGroupIndex;
}

QList<HDCDomeVideoPanel *> HDCDomeVideoContainer::getAllVideoPanels()
{
    return m_pwndVideoGroup->getAllVideoPanels();
}

void HDCDomeVideoContainer::setPanelResolution(int nVideoID,QString strResolution)
{
	m_pwndVideoGroup->setPanelResolution(nVideoID,strResolution);
}

void HDCDomeVideoContainer::setVideoSelectEnable(bool bEnable)
{
	m_pwndVideoGroup->setVideoSelectEnable(bEnable);
}

void HDCDomeVideoContainer::sltSetVideoCount(int nVideoCount)
{
	m_pwndVideoGroup->setVideoCount(nVideoCount);
	QList<HDCDomeVideoPanel*> lstPanels = m_pwndVideoGroup->getAllVideoPanels();

	int nDValue = nVideoCount - lstPanels.count();
	
	if(nDValue > 0)
	{
		for(int i = 0; i < nDValue; i ++)
		{
			HDCDomeVideoPanel *t_pvideoPanel = new HDCDomeVideoPanel(m_pwndVideoGroup);
			m_pwndVideoGroup->setVideoPanel(t_pvideoPanel);
			//m_lstVideos.append(t_pvideoPanel);
			connect(t_pvideoPanel,SIGNAL(sigPanelChecked()),m_pwndVideoGroup,SLOT(sltSetCurrentVideoPanel()));
			connect(t_pvideoPanel,SIGNAL(sigPanelDoubleClicked()),m_pwndVideoGroup,SLOT(sltPanelDoubleClicked()));
			//connect(t_pvideoPanel,SIGNAL(sigCloseCurrentVideo()),this,SIGNAL(sigCloseCurrentVideo()));
		    connect(t_pvideoPanel,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)),m_pwndVideoGroup,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)));
			connect(t_pvideoPanel,SIGNAL(sigCloseCurrentBroadCast()),m_pwndVideoGroup,SIGNAL(sigCloseCurrentBroadCast()));
			connect(t_pvideoPanel,SIGNAL(sigOpenCurrentVideoBroadCast()),m_pwndVideoGroup,SIGNAL(sigOpenCurrentVideoBroadCast()));
			connect(t_pvideoPanel,SIGNAL(sigViewWarningInfo()),m_pwndVideoGroup,SLOT(sltViewWarningInfo()));
			connect(t_pvideoPanel,SIGNAL(sigBitStreamChanged(int)),m_pwndVideoGroup,SLOT(sltBitStreamChanged(int)));
			connect(t_pvideoPanel,SIGNAL(sigVideoWarningStateChanged(QHash<QString,QVariant>,bool)),m_pwndVideoGroup,SIGNAL(sigVideoWarningStateChanged(QHash<QString,QVariant>,bool)));
			QString str;
		}
	}
	m_pwndVideoGroup->initGridInfo(nVideoCount);
	m_pwndVideoGroup->adjustSize();	
	//connect(m_pwndVideoGroup,SIGNAL(sigsetVideoCount(int)),this,SLOT(sltSetVideoCount(int)));
}

int HDCDomeVideoContainer::getCurrentVideoCount()
{
	return m_pwndVideoGroup->getCurrentVideoCount();
}

void HDCDomeVideoContainer::topVideoPanel(HDCDomeVideoPanel *videoPanel)
{
	m_pwndVideoGroup->topVideoPanel(videoPanel);
}

int HDCDomeVideoContainer::getCurrentPage()
{
	return m_pslAddVideoPage->currentIndex();
}

bool HDCDomeVideoContainer::isVideoPlaying()
{
	return m_pwndVideoGroup->isVideoPlaying();
}

bool HDCDomeVideoContainer::isVideoPanelGroupChecked()
{
	return m_pwndVideoGroup->isVideoPanelChecked();
}

int HDCDomeVideoContainer::getCurrentStackedLayoutWidgetIndex()
{
    return m_pslAddVideoPage->currentIndex();
}

void HDCDomeVideoContainer::pauseVideos(int nIndex)
{
	//停止当前页打开设备的媒体流
	m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(nIndex));
	QList<HDCDomeVideoPanel *> lstPauseVideo = m_pwndVideoGroup->getAllVideoPanels();
	QList<QString> lstPauseDevicedids;
	for (int i = 0; i < lstPauseVideo.count() ; i++)
	{
		QString strId = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstPauseVideo.at(i));
		lstPauseDevicedids<<strId;
		//取消当前窗口焦点
		m_pwndVideoGroup->setPanelChecked(i,false);
	}
	emit sigPauseVideo(lstPauseDevicedids);
}

void HDCDomeVideoContainer::continueVideos(int nIndex)
{
	//打开下页设备,如果有打开媒体流，继续打开
	m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(nIndex));
	QList<HDCDomeVideoPanel *> lstContinueVideo = m_pwndVideoGroup->getAllVideoPanels();
	QList<QString> lstContinueDevicedids;
	bool isOpen = false;
	for (int i = 0; i < lstContinueVideo.count() ; i++)
	{
		QString strId = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstContinueVideo.at(i));
		lstContinueDevicedids<<strId;

		//初始化当前窗口焦点为第一个窗口
		m_pwndVideoGroup->setPanelChecked(0,true);

		if (strId != "default")
		{
			isOpen = true;
		}
	}

	if (isOpen)
	{
		emit sigContinueVideo(lstContinueDevicedids);
	}
}

//重新计算堆栈布局窗口页码
void HDCDomeVideoContainer::calculateStackedLayoutWidgets()
{
	int nPage = m_pslAddVideoPage->count();
	int nCurrent = m_pslAddVideoPage->currentIndex();
	if (nPage >= 3)
	{
		if (nCurrent + 1 == nPage)
		{
			m_ppbPage1->show();
			m_ppbPage1->setText(QString("%1").arg(nCurrent));
			m_ppbPage2->show();
			m_ppbPage2->setText(QString("%1").arg(nCurrent + 1));
			m_ppbPage3->hide();
		}
		else if (nCurrent == 0)
		{
			m_ppbPage1->hide();
			m_ppbPage2->show();
			m_ppbPage2->setText(QString("%1").arg(nCurrent + 1));
			m_ppbPage3->show();
			m_ppbPage3->setText(QString("%1").arg(nCurrent + 2));
		}
		else
		{
			m_ppbPage1->show();
			m_ppbPage1->setText(QString("%1").arg(nCurrent));
			m_ppbPage2->show();
			m_ppbPage2->setText(QString("%1").arg(nCurrent + 1));
			m_ppbPage3->show();
			m_ppbPage3->setText(QString("%1").arg(nCurrent + 2));
		}
		m_pleTotalPage->setText(QString("%1").arg(nPage));
	}
	else
	{
		if (nPage == 2)
		{
			if (nCurrent == 0)
			{
				m_ppbPage1->hide();
				m_ppbPage2->show();
				m_ppbPage2->setText(QString("%1").arg(nPage-1));
				m_ppbPage3->show();
				m_ppbPage3->setText(QString("%1").arg(nPage));
			}
			else
			{
				m_ppbPage1->show();
				m_ppbPage1->setText(QString("%1").arg(nPage-1));
				m_ppbPage2->show();
				m_ppbPage2->setText(QString("%1").arg(nPage));
				m_ppbPage3->hide();
			}
		}
		else
		{
			m_ppbPage1->hide();
			m_ppbPage2->show();
			m_ppbPage2->setText(QString("%1").arg(nPage));
			m_ppbPage3->hide();
		}

		m_pleTotalPage->setText(QString("%1").arg(nPage));
	}	
}

void HDCDomeVideoContainer::recalculateStackedLayoutWidgets()
{
	int nCurrentIndex = 0;

	while ( nCurrentIndex < m_pslAddVideoPage->count())
	{
		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(nCurrentIndex));
		bool bIsVideoOpen = m_pwndVideoGroup->isHasOpenVideo();

		QList<QString> lstDeviceId;
		m_pwndVideoGroup->getAllDeviceIDs(lstDeviceId);

		//1213如果为空白页则删除
		if ( bIsVideoOpen == false)
		{	
			int nCount = m_pwndVideoGroup->getCurrentVideoCount();
			if (nCount == 1)
			{
				if ( (nCurrentIndex + 1) != m_pslAddVideoPage->count())
				{
					m_pslAddVideoPage->removeWidget(m_pwndVideoGroup);
				}
				else
				{
					nCurrentIndex++;
				}
			}
			//1213如果最后一页为空白页，但前页刚好满屏页，则该空白页不删除
			else if(lstDeviceId.count() != nCount)
			{
				m_pslAddVideoPage->removeWidget(m_pwndVideoGroup);
			}	
			else
			{
				nCurrentIndex++;
			}
		}
		else
		{
			nCurrentIndex++;
		}
	}
	calculateStackedLayoutWidgets();
}

//新增视频页处理  add lidandan 
void HDCDomeVideoContainer::addNewVideoPage(HDCDomeVideoPanel *videoPanel)
{
	m_iPageCount = m_pslAddVideoPage->count() + 1;
	int iCurrentVideoCount = m_pwndVideoGroup->getCurrentVideoCount();

	m_pwndVideoPage->show();
	m_pwndVideoGroup = new HDCDomeVideoGroup;
	sltSetVideoCount(iCurrentVideoCount);
	//m_nCurrentPanelOrder = 0;
	////设置每个VideoGroup的焦点,每次都点开下一页
	//m_pwndVideoGroup->setPanelChecked(0,true);

	m_pslAddVideoPage->addWidget(m_pwndVideoGroup);
	connect(m_pwndVideoGroup,SIGNAL(sigCloseVideo(HDCDomeVideoPanel *)),this,SLOT(sigCloseVideo(HDCDomeVideoPanel *)));

	//设置当前显示窗口添加页码前一页
	m_pslAddVideoPage->setCurrentIndex(m_iPageCount - 2);

	calculateStackedLayoutWidgets();

	//每新增一页时写绘制窗口配置信息
	HTVideoPanelConfig panelInfo;

	QString strDeviceId,strTaskId,strVideoName,strbitsteam,strResolution;
	QString strKey,strValue;
	int naddpage = m_pslAddVideoPage->currentIndex() + 1;
	m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup*>(m_pslAddVideoPage->widget(naddpage));
	QList<HDCDomeVideoPanel*> lstPanels = m_pwndVideoGroup->getAllVideoPanels();
	for (int npanels = 0; npanels < lstPanels.count(); npanels++)
	{
		panelInfo = getCurrentVideoPanelConfig(lstPanels.at(npanels));
		strDeviceId = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstPanels.at(npanels));
		strbitsteam = lstPanels.at(npanels)->getResolution();

		//1224多屏显示时，写每页绘制窗口的配置信息
		if (strDeviceId == "default")
		{
			//strDeviceId = QString("default%1").arg(npanels);
			strKey =  QString("VideoPanelIndexInfo:%1_page%2index%3").arg(strDeviceId).arg(panelInfo.m_nPageIndex).arg(npanels) ;
		}
		else
		{
			strKey =  "VideoPanelIndexInfo:" + strDeviceId;
		}
		strValue  = QString(" PageCount=%1; PageINdex=%2; PanelPos=%3; VideoCount=%4; DeviceID=%5; TaskID=%6; VideoName=%7; BitSteam=%8; Resolution=%9; ").
			arg(panelInfo.m_nPage).arg(panelInfo.m_nPageIndex).arg(panelInfo.m_nPos).arg(panelInfo.m_nVideoCount).arg(strDeviceId).arg(strTaskId).arg(strVideoName).arg(strbitsteam).arg(strResolution);
		writeScenesConfig(strKey,strValue);
	}
}

//对某镜头设备重新排版，关闭原来打开设备
HDCDomeVideoPanel* HDCDomeVideoContainer::findOpenedVideo(QString strDeviceID)
{
	bool bHasVideoPanel = false;
	int nCurrentVideoGroupIndex = m_pslAddVideoPage->currentIndex();

	HDCDomeVideoPanel *pwndDeleteVideoPanel;
	QList<HDCDomeVideoPanel*> lstAllVideoPanels;
	int nStackedLayoutWidgetCount = m_pslAddVideoPage->count();
	for ( int i = 0; i< nStackedLayoutWidgetCount; i++ )
	{
		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(i));
		pwndDeleteVideoPanel = m_pwndVideoGroup->getVideoPanel(strDeviceID);
		lstAllVideoPanels = m_pwndVideoGroup->getAllVideoPanels();

		for(int j = 0; j < lstAllVideoPanels.count(); j++)
		{
			if (pwndDeleteVideoPanel == lstAllVideoPanels.at(j))
			{
				return pwndDeleteVideoPanel;
			}
		}
	}
}

void HDCDomeVideoContainer::paintEvent(QPaintEvent *event)
{
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    QWidget::paintEvent(event);
}

void HDCDomeVideoContainer::writeScenesConfig(QString strKey, QString strValue)
{
	//判断原来配置信息中是否在相同位置（某页某位置）已存在绘制窗口，如果存在，删除旧的，添加新的配置信息
	QString strnewpageIndex,strnewpos,strnewvideocount,strnewpagecount;
	strnewpageIndex = getConfigValue("PageINdex=",strValue);
	strnewpos = getConfigValue("PanelPos=",strValue);
	strnewvideocount = getConfigValue("VideoCount=",strValue);
	strnewpagecount = getConfigValue("PageCount=",strValue);

	//写配置前读出所有的配置信息，判断配置文件中是否已存在该绘制窗口配置信息，如果有则删除原来的，添加新的配置内容
	QString strReadFile = g_strAppPath + XMLRELATIONPATH + "miansettingConfig.xml";
	HSettingConfigOperator::readConfig(m_hashScenesInfo,strReadFile);
	QList<QString> lstStrKey = m_hashScenesInfo.keys();
	QString stroldValue,strpageIndex,strpos,strvideocount,strpagecount;
	int nstart,nlength;
	for (int i = 0; i < lstStrKey.count(); i++)
	{
		//改写配置文件中每个绘制窗口的总页数与屏数
		strpagecount = getConfigValue("PageCount=",m_hashScenesInfo.value(lstStrKey.at(i)));
		if (strpagecount != strnewpagecount)
		{
			m_hashScenesInfo[lstStrKey.at(i)] = setConfigValue("PageCount=",strnewpagecount,m_hashScenesInfo.value(lstStrKey.at(i)));
		}
		strvideocount = getConfigValue("VideoCount=",m_hashScenesInfo.value(lstStrKey.at(i)));
		if (strvideocount != strnewvideocount)
		{
			m_hashScenesInfo[lstStrKey.at(i)] = setConfigValue("VideoCount=",strnewvideocount,m_hashScenesInfo.value(lstStrKey.at(i)));
		}

		//删除配置文件中相同配置的绘制窗口配置信息
		strpageIndex = getConfigValue("PageINdex=",m_hashScenesInfo.value(lstStrKey.at(i)));
		strpos = getConfigValue("PanelPos=",m_hashScenesInfo.value(lstStrKey.at(i)));		
		if ((strnewpageIndex == strpageIndex) && (strnewpos == strpos))
		{
			m_hashScenesInfo.remove(lstStrKey.at(i));
		}
	}

	m_hashScenesInfo[strKey] = strValue;

	QString strFile = "miansettingConfig";
	QString strPath = g_strAppPath + XMLRELATIONPATH;
	HSettingConfigOperator::writeConfig(m_hashScenesInfo,strFile,strPath);

}

QString HDCDomeVideoContainer::getConfigValue(QString str, QString strValue)
{
	int nstart,nlength,nstrlength;
	nstrlength = str.length();
	nstart = strValue.indexOf(str) + nstrlength;
	nlength  = strValue.indexOf(";",nstart) - nstart;
	return strValue.mid(nstart,nlength);
}

QString HDCDomeVideoContainer::setConfigValue(QString str,QString strValue,QString strItemValue)
{
	int nstart,nlength,nstrlength;
	nstrlength = str.length();
	nstart = strItemValue.indexOf(str) + nstrlength;
	nlength  = strItemValue.indexOf(";",nstart) - nstart;
	strItemValue = strItemValue.replace(nstart,nlength,strValue);
	return strItemValue;
}

void HDCDomeVideoContainer::readScenesConfig(QHash<QString,QString> &hashScenesConfig)
{
	QString strReadFile = g_strAppPath + XMLRELATIONPATH + "miansettingConfig.xml";
	HSettingConfigOperator::readConfig(hashScenesConfig,strReadFile);	
}

void HDCDomeVideoContainer::recoveryScenes()
{
	//读配置信息
	QHash<QString,QString> hashScenesConfig;
	readScenesConfig(hashScenesConfig);
	
	//初始化场景
	QString strValue;
	int nPagesCount,npageIndex,nVideoCount,nVideoPos,nBitSteam;
	QString strDeviceId,strVideoName,strResolution,strVideo,strTaskId;
	QList<QString> lstStrKey = hashScenesConfig.keys();
	if (lstStrKey.count() > 0)
	{
		//页数、屏数不变
		strValue = hashScenesConfig.value(lstStrKey.at(0));
		nPagesCount = getConfigValue("PageCount=",strValue).toInt();
		nVideoCount = getConfigValue("VideoCount=",strValue).toInt();
	}

	QList<HDCDomeVideoPanel*> lstVideoPanels;
	QHash<QString,QVariant> hashVideoData;
	QVariant varData;
	for (int npage = 0; npage < nPagesCount; npage++)
	{
		//处理每一页打开的设备
		m_pwndVideoGroup = new HDCDomeVideoGroup;
		m_pslAddVideoPage->addWidget(m_pwndVideoGroup);
		sltSetVideoCount(nVideoCount);
		m_pwndVideoGroup->setPanelChecked(0,true);
	}	
}

HTVideoPanelConfig HDCDomeVideoContainer::getCurrentVideoPanelConfig(HDCDomeVideoPanel *t_pvideoPanel)
{
	HTVideoPanelConfig panelInfo;
	for (int npage = 0; npage < m_pslAddVideoPage->count(); npage++)
	{
		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(npage));
		QList<HDCDomeVideoPanel*> lstVideoPanels = m_pwndVideoGroup->getAllVideoPanels();

		HTVideoPanelConfig panelInfo;
		for(int nVideoPanel = 0; nVideoPanel < lstVideoPanels.count(); nVideoPanel++)
		{
			if (t_pvideoPanel == lstVideoPanels.at(nVideoPanel))
			{
				panelInfo.m_nPage = m_pslAddVideoPage->count();
				panelInfo.m_nPageIndex = npage;
				panelInfo.m_nPos = nVideoPanel;
				panelInfo.m_nVideoCount = m_pwndVideoGroup->getCurrentVideoCount();
				panelInfo.m_nDeviceID = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstVideoPanels.at(nVideoPanel)).toInt();
				
				return panelInfo;
			}
		}
	}

}

void HDCDomeVideoContainer::newVideoPanel(HDCDomeVideoGroup *videoGroup)
{
	HDCDomeVideoPanel *t_pvideoPanel = new HDCDomeVideoPanel(videoGroup);
	//lstAllVideoPanels.append(t_pvideoPanel);
	videoGroup->setVideoPanel(t_pvideoPanel);
	//增加新建panel的信号-槽连接
	connect(t_pvideoPanel,SIGNAL(sigPanelChecked()),m_pwndVideoGroup,SLOT(sltSetCurrentVideoPanel()));
	connect(t_pvideoPanel,SIGNAL(sigPanelDoubleClicked()),m_pwndVideoGroup,SLOT(sltPanelDoubleClicked()));
	//connect(t_pvideoPanel,SIGNAL(sigCloseCurrentVideo()),this,SIGNAL(sigCloseCurrentVideo()));
	connect(t_pvideoPanel,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)),m_pwndVideoGroup,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)));
	connect(t_pvideoPanel,SIGNAL(sigCloseCurrentBroadCast()),m_pwndVideoGroup,SIGNAL(sigCloseCurrentBroadCast()));
	connect(t_pvideoPanel,SIGNAL(sigOpenCurrentVideoBroadCast()),m_pwndVideoGroup,SIGNAL(sigOpenCurrentVideoBroadCast()));
	connect(t_pvideoPanel,SIGNAL(sigViewWarningInfo()),m_pwndVideoGroup,SLOT(sltViewWarningInfo()));
	connect(t_pvideoPanel,SIGNAL(sigBitStreamChanged(int)),m_pwndVideoGroup,SLOT(sltBitStreamChanged(int)));
	connect(t_pvideoPanel,SIGNAL(sigVideoWarningStateChanged(QHash<QString,QVariant>,bool)),m_pwndVideoGroup,SIGNAL(sigVideoWarningStateChanged(QHash<QString,QVariant>,bool)));
//	connect(t_pvideoPanel,SIGNAL(sigVideoPanelChanged(HDCDomeVideoPanel*)),m_pwndVideoGroup,SIGNAL(sigVideoPanelChanged(HDCDomeVideoPanel*)));
}

void HDCDomeVideoContainer::videoPanelConnections(HDCDomeVideoPanel *pvideoPanel)
{
	if (pvideoPanel)
	{
		connect(pvideoPanel,SIGNAL(sigPanelChecked()),m_pwndVideoGroup,SLOT(sltSetCurrentVideoPanel()));
		connect(pvideoPanel,SIGNAL(sigPanelDoubleClicked()),m_pwndVideoGroup,SLOT(sltPanelDoubleClicked()));
		//connect(pvideoPanel,SIGNAL(sigCloseCurrentVideo()),this,SIGNAL(sigCloseCurrentVideo()));
		connect(pvideoPanel,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)),m_pwndVideoGroup,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)));
		connect(pvideoPanel,SIGNAL(sigCloseCurrentBroadCast()),m_pwndVideoGroup,SIGNAL(sigCloseCurrentBroadCast()));
		connect(pvideoPanel,SIGNAL(sigOpenCurrentVideoBroadCast()),m_pwndVideoGroup,SIGNAL(sigOpenCurrentVideoBroadCast()));
		connect(pvideoPanel,SIGNAL(sigViewWarningInfo()),m_pwndVideoGroup,SLOT(sltViewWarningInfo()));
		connect(pvideoPanel,SIGNAL(sigBitStreamChanged(int)),m_pwndVideoGroup,SLOT(sltBitStreamChanged(int)));
		connect(pvideoPanel,SIGNAL(sigVideoWarningStateChanged(QHash<QString,QVariant>,bool)),m_pwndVideoGroup,SIGNAL(sigVideoWarningStateChanged(QHash<QString,QVariant>,bool)));
//		connect(pvideoPanel,SIGNAL(sigVideoPanelChanged(HDCDomeVideoPanel*)),m_pwndVideoGroup,SIGNAL(sigVideoPanelChanged(HDCDomeVideoPanel*)));
	}
}

void HDCDomeVideoContainer::clearXmlFileVideoPanelConfig()
{
	//写配置前读出所有的配置信息，清除绘制窗口相关的配置信息
	QString strReadFile = g_strAppPath + XMLRELATIONPATH + "miansettingConfig.xml";
	HSettingConfigOperator::readConfig(m_hashScenesInfo,strReadFile);
	QList<QString> lstStrKey = m_hashScenesInfo.keys();
	for (int i = 0; i < lstStrKey.count(); i++)
	{
		if (lstStrKey.at(i).contains("VideoPanelIndexInfo"))
		{
			m_hashScenesInfo.remove(lstStrKey.at(i));
		}
	}

	QString strFile = "miansettingConfig";
	QString strPath = g_strAppPath + XMLRELATIONPATH;
	HSettingConfigOperator::writeConfig(m_hashScenesInfo,strFile,strPath);
}

void HDCDomeVideoContainer::saveChangedVideoCountConfigInfo(HDCDomeVideoPanel *pwndvideopanel, int npos,int npageindex,int npagecount)
{
	QString strDeviedID,strTaskID,strVideoName,strResolution;
    int nVideoCount,nBitSteam;
	QString strKey,strValue;
	strDeviedID = m_pwndVideoGroup->getDeviceIDFromVideoPanel(pwndvideopanel);
	//nPagesCount = m_pslAddVideoPage->count();
	//nPageIndex = m_pslAddVideoPage->currentIndex();
	nVideoCount = m_pwndVideoGroup->getCurrentVideoCount();
	strVideoName = pwndvideopanel->getVideoName();
	strResolution = pwndvideopanel->getResolution();
	nBitSteam = pwndvideopanel->getBitSteam();

	if (strDeviedID == "default")
	{
		//strDeviedID = QString("default%1").arg(nPageIndex);
		strKey = QString("VideoPanelIndexInfo:%1_page%2index%3").arg(strDeviedID).arg(npageindex).arg(npos);
	}
	else
	{
		strKey = "VideoPanelIndexInfo:" + strDeviedID;
	}	
	strValue  = QString(" PageCount=%1; PageINdex=%2; PanelPos=%3; VideoCount=%4; DeviceID=%5; TaskID=%6; VideoName=%7; BitSteam=%8; Resolution=%9; ")\
		.arg(npagecount).arg(npageindex).arg(npos).arg(nVideoCount).arg(strDeviedID).arg(strTaskID).arg(strVideoName).arg(nBitSteam).arg(strResolution);
	
	writeScenesConfig(strKey, strValue);
}

void HDCDomeVideoContainer::initUI()
{
    this->setObjectName("dc_wnd_videoContainer");
    m_pvblMain = new QVBoxLayout();
    m_pvblMain->setSpacing(0);
    m_pvblMain->setContentsMargins(1,0,0,0);

    m_phblToolbar = new QHBoxLayout();
    m_phblToolbar->setSpacing(20);
    m_phblToolbar->setContentsMargins(20,0,0,0);

    m_phblStatusBar = new QHBoxLayout();
    m_phblStatusBar->setSpacing(20);
    m_phblStatusBar->setContentsMargins(20,0,20,0);

    m_pglpopScreenSelect = new QGridLayout();
    m_pglpopScreenSelect->setSpacing(15);
    m_pglpopScreenSelect->setContentsMargins(20,20,20,20);

	//增加堆栈布局
	m_pslAddVideoPage = new QStackedLayout(); 
	m_pslAddVideoPage->setSpacing(20);
	//m_pslAddVideoPage->setContentsMargins(20,40,20,40);
	//m_pslAddVideoPage->setCurrentIndex(0);

	m_phblVideoPage = new QHBoxLayout(); 
	m_phblVideoPage->setSpacing(20);
	m_phblVideoPage->setContentsMargins(20,0,20,0);	

    m_pwndToolBar = new QWidget(this);
	//m_pwndToolBar = new HClickableWidget(this);
    m_pwndToolBar->setObjectName("dc_wnd_videoContainer_toolbar");

    m_ppbSplitScreen = new QPushButton(m_pwndToolBar);
    m_ppbSplitScreen->setFixedSize(NSAVEBTNWIDTH,NSAVEBTNHEIGHT);
    m_ppbSplitScreen->setObjectName("dc_btn_withText");
    m_ppbSplitScreen->setText(QString::fromLocal8Bit("分屏"));
	m_ppbSplitScreen->setToolTip(QString::fromLocal8Bit("分屏"));

    m_plblSpliter = new QLabel(m_pwndToolBar);
    m_plblSpliter->setFixedSize(1,25);
    m_plblSpliter->setObjectName("dc_lbl_spliter");

	m_ppbHangOnAll = new QPushButton();
	m_ppbHangOnAll->setFixedSize(g_nCameraControlBtnWidth,g_nCameraControlBtnWidth);
	m_ppbHangOnAll->setObjectName("dc_btn_hangOn");
	m_ppbHangOnAll->setToolTip(QString::fromLocal8Bit("全部挂断"));

 	m_ppbShowStateChange = new QPushButton();
 	m_ppbShowStateChange->setFixedSize(g_nCameraControlBtnWidth,g_nCameraControlBtnWidth);
 	m_ppbShowStateChange->setObjectName("dc_btn_showFullScrren");
 	m_ppbShowStateChange->setToolTip(QString::fromLocal8Bit("全屏显示"));

	m_pwndClickable = new HClickableWidget(m_pwndToolBar);
	m_pwndClickable->setFixedSize(60,40);

	m_plbTourPlay = new QLabel(m_pwndToolBar);
	m_plbTourPlay->setObjectName("dc_lbl_tour");
	m_plbTourPlay->setText(QString::fromLocal8Bit("轮巡"));
	//m_plbTourPlay->setFixedSize(1,25);
	m_plbTourPlay->adjustSize();

	m_ppbTourOpen = new QPushButton(m_pwndToolBar);
	m_ppbTourOpen->setObjectName("dc_btn_touropen");
	m_ppbTourOpen->setText(QString::fromLocal8Bit("打开"));
	m_ppbTourOpen->setMaximumWidth(45);
	m_ppbTourOpen->adjustSize();
	m_ppbTourOpen->setStyleSheet("background-color:#8A8A8A");

	m_ppbTourClose = new QPushButton(m_pwndToolBar);
	m_ppbTourClose->setObjectName("dc_btn_tourclose");
	m_ppbTourClose->setText(QString::fromLocal8Bit("关闭"));
	m_ppbTourClose->setMaximumWidth(45);
	m_ppbTourClose->adjustSize();
	m_ppbTourClose->setStyleSheet("background-color:#555555");

	//改为恢复场景
   // m_pwndVideoGroup = new HDCDomeVideoGroup();	
   // setVideoCount(1); 
	//取消初始化时焦点
   // m_pwndVideoGroup->setPanelChecked(0,true);
	//m_pwndVideoGroup->setCurrentVideoPanel(0);

    m_pwndStatusBar = new QWidget();
    m_pwndStatusBar->setObjectName("dc_wnd_videoContainer_statusbar");

    m_plblCPUAndMemery = new QLabel();
    m_plblCPUAndMemery->setObjectName("dc_lbl_sliderSpeed");
    m_plblCPUAndMemery->setText(m_strCPUAndMemery);

    m_plblCurrentTime = new QLabel();
    m_plblCurrentTime->setObjectName("dc_lbl_sliderSpeed");
    m_plblCurrentTime->setText("2016.08.26 17:55:55");

	m_plblLogo = new QLabel();
	m_plblLogo->setPixmap(QPixmap(QApplication::applicationDirPath() + g_strImageRelationPath + "HIDI_LOGO2.png"));

    m_pwndPopScreenSelect = new QWidget();
    m_pwndPopScreenSelect->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
    m_pwndPopScreenSelect->setObjectName("dc_wnd_popScreenSelect");
    //m_pwndPopScreenSelect->setFixedSize(400,150);

    QFile file(g_strAppPath + QSSRELATIONPATH + "HDomeControlPanel.qss");
    if(file.open(QIODevice::ReadOnly))
    {
        QString strStyle = file.readAll();
        m_pwndPopScreenSelect->setStyleSheet(strStyle.arg(g_strAppPath + g_strImageRelationPath));
    }

    m_pbgPopScreenSelect = new QButtonGroup(m_pwndPopScreenSelect);
    m_pbgPopScreenSelect->setExclusive(true);

	//单屏显示
    m_ppb1Video = new QPushButton();
   // m_ppb1Video->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
	m_ppb1Video->setFixedSize(NSPLITSCREENWIDTH,NSPLITSCREENHEIGHT);
    m_ppb1Video->setObjectName("dc_btn_video1");
    m_ppb1Video->setCheckable(true);
    m_ppb1Video->setFlat(true);
    m_ppb1Video->setChecked(true);
    m_pbgPopScreenSelect->addButton(m_ppb1Video,1);

	//四屏显示
    m_ppb4Video = new QPushButton();
    //m_ppb4Video->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
	m_ppb4Video->setFixedSize(NSPLITSCREENWIDTH,NSPLITSCREENHEIGHT);
    m_ppb4Video->setObjectName("dc_btn_video4");
    m_ppb4Video->setCheckable(true);
    m_ppb4Video->setFlat(true);
    m_pbgPopScreenSelect->addButton(m_ppb4Video,4);

	//6屏显示
    m_ppb6Video = new QPushButton();   
    //m_ppb6Video->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
	m_ppb6Video->setFixedSize(NSPLITSCREENWIDTH,NSPLITSCREENHEIGHT);
    m_ppb6Video->setObjectName("dc_btn_video6");
    m_ppb6Video->setCheckable(true);
    m_ppb6Video->setFlat(true);
    m_pbgPopScreenSelect->addButton(m_ppb6Video,6);

	//9屏显示
    m_ppb9Video = new QPushButton();
    //m_ppb9Video->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
	m_ppb9Video->setFixedSize(NSPLITSCREENWIDTH,NSPLITSCREENHEIGHT);
    m_ppb9Video->setObjectName("dc_btn_video9");
    m_ppb9Video->setCheckable(true);
    m_ppb9Video->setFlat(true);
    m_pbgPopScreenSelect->addButton(m_ppb9Video,9);

	//16屏显示
    m_ppb16Video = new QPushButton();
    //m_ppb16Video->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
	m_ppb16Video->setFixedSize(NSPLITSCREENWIDTH,NSPLITSCREENHEIGHT);
    m_ppb16Video->setObjectName("dc_btn_video16");
    m_ppb16Video->setCheckable(true);
    m_ppb16Video->setFlat(true);
    m_pbgPopScreenSelect->addButton(m_ppb16Video,16);

	//视频分页选择窗口
	m_pwndVideoPage = new QWidget(this); 
	m_pwndVideoPage->setObjectName("dc_wnd_videoContainer_videopage");

	m_ppbPreviousPage = new QPushButton(m_pwndVideoPage);
	m_ppbPreviousPage->setFlat(true);
	m_ppbPreviousPage->setFixedSize(40,20);
	m_ppbPreviousPage->setObjectName("dc_btn_prepage");
	m_ppbPreviousPage->setText(QString::fromLocal8Bit("上一页"));

	m_ppbPage1 = new QPushButton(m_pwndVideoPage);
	m_ppbPage1->setFlat(true);
	m_ppbPage1->setFixedSize(20,20);
	m_ppbPage1->setObjectName("dc_btn_page1");
	m_ppbPage1->setText(QString::fromLocal8Bit("1"));

	m_ppbPage2 = new QPushButton(m_pwndVideoPage);
	//m_ppbPage2->setFlat(true);
	m_ppbPage2->setFixedSize(20,20);
	m_ppbPage2->setObjectName("dc_btn_page2");
	m_ppbPage2->setText(QString::fromLocal8Bit("2"));
	m_ppbPage2->setStyleSheet("QPushButton{background:blue}");

	m_ppbPage3 = new QPushButton(m_pwndVideoPage);
	m_ppbPage3->setFlat(true);
	m_ppbPage3->setFixedSize(20,20);
	m_ppbPage3->setObjectName("dc_btn_page3");
	m_ppbPage3->setText(QString::fromLocal8Bit("3"));

	m_ppbNextPage = new QPushButton(m_pwndVideoPage);
	m_ppbNextPage->setFlat(true);
	m_ppbNextPage->setFixedSize(40,20);
	m_ppbNextPage->setObjectName("dc_btn_nextpage");
	m_ppbNextPage->setText(QString::fromLocal8Bit("下一页"));

	m_plbTotalPage = new QLabel(m_pwndVideoPage);
	m_plbTotalPage->setObjectName("dc_lbl_totalpage");
	m_plbTotalPage->setText(QString::fromLocal8Bit("共"));

	m_pleTotalPage = new QLineEdit(m_pwndVideoPage);
	m_pleTotalPage->setObjectName("dc_lel_totalpage");
	m_pleTotalPage->setFixedSize(20,20);
	//m_pleTotalPage->setText(QString::fromLocal8Bit("0"));
	m_pleTotalPage->setText("0");

	m_plbPageCount = new QLabel(m_pwndVideoPage);
	m_plbPageCount->setObjectName("dc_lbl_pagecount");
	m_plbPageCount->setText(QString::fromLocal8Bit("页"));

	m_plbJump = new QLabel(m_pwndVideoPage);
	m_plbJump->setObjectName("dc_lbl_jumppage");
	m_plbJump->setText(QString::fromLocal8Bit("跳转到"));

	m_pleJumpPage = new QLineEdit(m_pwndVideoPage);	
	m_pleJumpPage->setObjectName("dc_lel_jumpeditpage");
	m_pleJumpPage->setFixedSize(20,20);
	m_pleJumpPage->setText(QString::fromLocal8Bit("1"));

	m_plbPage = new QLabel(m_pwndVideoPage);
	m_plbPage->setObjectName("dc_lbl_jumppage");
	m_plbPage->setText(QString::fromLocal8Bit("页"));

	m_ppbGo = new QPushButton(m_pwndVideoPage);
	m_ppbGo->setFlat(false);
	m_ppbGo->setFixedSize(40,20);
	m_ppbGo->setObjectName("dc_btn_nextpage");
	m_ppbGo->setText(QString::fromLocal8Bit("Go"));

    m_phblToolbar->addWidget(m_ppbSplitScreen);
    m_phblToolbar->addWidget(m_plblSpliter);
    m_phblToolbar->addWidget(m_ppbHangOnAll);
	m_phblToolbar->addWidget(m_ppbShowStateChange);
	m_phblToolbar->addStretch(1);
	m_phblToolbar->addWidget(m_pwndClickable);
	m_phblToolbar->addStretch(3);
	m_phblToolbar->addWidget(m_plbTourPlay);
	m_phblToolbar->addWidget(m_ppbTourOpen);
	m_phblToolbar->addWidget(m_ppbTourClose);
	m_pwndToolBar->setLayout(m_phblToolbar);

    m_phblStatusBar->addWidget(m_plblCPUAndMemery);
    m_phblStatusBar->addWidget(m_plblCurrentTime);
	m_phblStatusBar->addStretch(100);
	m_phblStatusBar->addWidget(m_plblLogo);
    m_pwndStatusBar->setLayout(m_phblStatusBar);

	m_phblVideoPage->addStretch(20);
	m_phblVideoPage->addWidget(m_ppbPreviousPage);
	m_phblVideoPage->addWidget(m_ppbPage1);
	m_ppbPage1->hide();
	m_phblVideoPage->addWidget(m_ppbPage2);
	m_ppbPage2->hide();
	m_phblVideoPage->addWidget(m_ppbPage3);
	m_ppbPage3->hide();
	m_phblVideoPage->addWidget(m_ppbNextPage);
	m_phblVideoPage->addWidget(m_plbTotalPage);
	m_phblVideoPage->addWidget(m_pleTotalPage);
	m_phblVideoPage->addWidget(m_plbPageCount);	
	m_phblVideoPage->addWidget(m_plbJump);
	m_phblVideoPage->addWidget(m_pleJumpPage);
	m_phblVideoPage->addWidget(m_plbPage);
	m_phblVideoPage->addWidget(m_ppbGo);
	m_phblVideoPage->addStretch(20);
	m_pwndVideoPage->setLayout(m_phblVideoPage);
	m_pwndVideoPage->hide();

	//m_pslAddVideoPage->addWidget(m_pwndVideoGroup);
	//m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);	
	m_pslAddVideoPage->setCurrentIndex(0);

    m_pvblMain->addWidget(m_pwndToolBar,1);
    //m_pvblMain->addWidget(m_pwndVideoGroup,18);
	m_pvblMain->addLayout(m_pslAddVideoPage,18);
	m_pvblMain->addWidget(m_pwndVideoPage,1);//add lidandan
    m_pvblMain->addWidget(m_pwndStatusBar,1);

    this->setLayout(m_pvblMain);

    m_pglpopScreenSelect->addWidget(m_ppb1Video,0,0,1,1);
    m_pglpopScreenSelect->addWidget(m_ppb4Video,0,1,1,1);
    m_pglpopScreenSelect->addWidget(m_ppb6Video,0,2,1,1);
    m_pglpopScreenSelect->addWidget(m_ppb9Video,1,0,1,1);
    m_pglpopScreenSelect->addWidget(m_ppb16Video,1,1,1,1);
    m_pwndPopScreenSelect->setLayout(m_pglpopScreenSelect);
	m_pwndPopScreenSelect->adjustSize();
    m_pwndPopScreenSelect->hide();

	recoveryScenes();

    connect(m_pbgPopScreenSelect,SIGNAL(buttonClicked(int)),this,SLOT(sltSetScreenVideo(int)));//
    connect(m_ppbSplitScreen,SIGNAL(clicked()),this,SLOT(sltShowPopScreenSelect()));
    //connect(m_pwndVideoGroup,SIGNAL(sigCloseCurrentVideo()),this,SIGNAL(sigCloseCurrentVideo()));
	connect(m_pwndVideoGroup,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)),this,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)));
    connect(m_pwndVideoGroup,SIGNAL(sigCloseCurrentBroadCast()),this,SIGNAL(sigCloseCurrentBroadCast()));
    connect(m_pwndVideoGroup,SIGNAL(sigOpenCurrentVideoBroadCast()),this,SIGNAL(sigOpenCurrentVideoBroadCast()));
	connect(m_pwndVideoGroup,SIGNAL(sigVideoLayoutChanged()),this,SIGNAL(sigVideoLayoutChanged()));
	connect(m_pwndVideoGroup,SIGNAL(sigVideoWarningStateChanged(QHash<QString,QVariant>,bool)),this,SIGNAL(sigVideoWarningStateChanged(QHash<QString,QVariant>,bool)));
	connect(m_ppbHangOnAll,SIGNAL(clicked()),this,SIGNAL(sigCloseAllVideo()));
	connect(m_ppbShowStateChange,SIGNAL(clicked()),this,SLOT(sltShowStateChanged()));
    connect(m_pwndVideoGroup,SIGNAL(sigBitStreamChanged(int,HDCDomeVideoPanel*)),this,SIGNAL(sigBitStreamChanged(int,HDCDomeVideoPanel*)));
	connect(m_pwndToolBar,SIGNAL(sigMouseDoubleClicked()),this,SLOT(sltShowStateChanged()));
	connect(m_pwndClickable,SIGNAL(sigMouseClicked()),this,SIGNAL(sigReOpenVideos()));
	//connect(m_pwndVideoGroup,SIGNAL(sigVideoPanelChanged(HDCDomeVideoPanel*)),this,SLOT(sltVideoPanelChanged(HDCDomeVideoPanel*)));
	//connect(m_pwndVideoGroup,SIGNAL(sigsetVideoCout(int)),this,SLOT(sltSetVideoCount(int)));

	connect(m_ppbPreviousPage,SIGNAL(clicked()), this, SLOT(sltTurnPreviousPage()));
	connect(m_ppbPage1,SIGNAL(clicked()), this, SLOT(sltTurnPage1()));
	connect(m_ppbPage2,SIGNAL(clicked()), this, SLOT(sltTurnPage2()));
	connect(m_ppbPage3,SIGNAL(clicked()), this, SLOT(sltTurnPage3()));
	connect(m_ppbNextPage,SIGNAL(clicked()), this, SLOT(sltTurnNextPage()));
	connect(m_ppbGo,SIGNAL(clicked()), this, SLOT(sltJumpToPage()));
	connect(m_pleJumpPage,SIGNAL(returnPressed()),m_ppbGo,SIGNAL(clicked()),Qt::UniqueConnection);

	connect(m_ppbTourOpen,SIGNAL(clicked()),this,SLOT(sltTourPlayStart()));
	connect(m_ppbTourClose,SIGNAL(clicked()),this,SLOT(sltTourPlayClose()));
	
	if (m_pslAddVideoPage->count() > 1)
	{
		m_pwndVideoPage->show();
		calculateStackedLayoutWidgets();
	}
}

QList<QString>  HDCDomeVideoContainer::getAllOpenVideoIdsFromXml()
{
	QList<QString> lstStringIds;
	//读配置信息
	QHash<QString,QString> hashScenesConfig;
	readScenesConfig(hashScenesConfig);
	QList<QString> lststrkeys = hashScenesConfig.keys();
	
	for (int nkey = 0; nkey < lststrkeys.count(); nkey++)
	{
		QString strId = getConfigValue("DeviceID=",hashScenesConfig.value(lststrkeys.at(nkey)));
		if (strId != "default")
		{
			lstStringIds<<strId;
		}
	}
	return lstStringIds;
}

void HDCDomeVideoContainer::initOpenVideo(QString strOpenDeviceId)
{
	//读配置信息
	QHash<QString,QString> hashScenesConfig;
	readScenesConfig(hashScenesConfig);
	QList<QString> lststrkeys = hashScenesConfig.keys();

	QString strPageIndex,strPos,strVideoName,strBitSteam,strResolution,strTaskId;
	QString strDevicedId,strVideo;
	for (int nkey = 0; nkey < lststrkeys.count(); nkey++)
	{
		strDevicedId = getConfigValue("DeviceID=",hashScenesConfig.value(lststrkeys.at(nkey)));
		if (strDevicedId == strOpenDeviceId)
		{
			strPos = getConfigValue("PanelPos=",hashScenesConfig.value(lststrkeys.at(nkey)));
			strPageIndex = getConfigValue("PageINdex=",hashScenesConfig.value(lststrkeys.at(nkey)));
			m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(strPageIndex.toInt()));
			QList<HDCDomeVideoPanel*> lstPanels = m_pwndVideoGroup->getAllVideoPanels();

			QHash<QString,QVariant> hashVideoData;
			QVariant varData;

			strVideoName = getConfigValue("VideoName=",hashScenesConfig.value(lststrkeys.at(nkey)));
			strBitSteam = getConfigValue("BitSteam=",hashScenesConfig.value(lststrkeys.at(nkey)));
			strResolution = getConfigValue("Resolution=",hashScenesConfig.value(lststrkeys.at(nkey)));
			strTaskId = getConfigValue("TaskID=",hashScenesConfig.value(lststrkeys.at(nkey)));
			//"deviceID:default,taskID:default" 
			strVideo = QString("deviceID:%1,taskID:%2").arg(strOpenDeviceId).arg(strTaskId);
			hashVideoData.insert(VIDEO,strOpenDeviceId.toInt());
			hashVideoData.insert(VIDEONAME,strVideoName);
			hashVideoData.insert(BITSTREAM,strBitSteam);

			varData = QVariant(hashVideoData);
			lstPanels.at(strPos.toInt())->setData(varData);

			emit sigRecoveryScenesOpenVideos(lstPanels.at(strPos.toInt()), varData);

			//停止播放其他页面视频流
			if (strPageIndex.toInt() != 0)
			{
				pauseVideos(strPageIndex.toInt());
			}
		}
	}
}

void HDCDomeVideoContainer::sltUpdateRealTimeData()
{
	m_nCPUValue = get_cpu_usage();
	
	PROCESS_MEMORY_COUNTERS pmc;
	get_memory_usage(&pmc);
	unsigned __int64 nProsMem = pmc.WorkingSetSize;

	unsigned __int64 nMemTotal;
	MEMORYSTATUSEX memsStat;  
	memsStat.dwLength = sizeof(memsStat);  
	if(!GlobalMemoryStatusEx(&memsStat))//如果获取系统内存信息不成功，就直接返回  
	{  
		nMemTotal = -1;    
		return;  
	}   

	nMemTotal = (memsStat.ullTotalPhys); 
	
	float fMemUsed = (nProsMem * 1.0) / nMemTotal;

	int t_nMemeryValue = fMemUsed * 10000;
	m_fMemeryValue = t_nMemeryValue / 100.0;

	m_strCPUAndMemery = QString::fromLocal8Bit("CPU:%1%  内存:%2%").arg(m_nCPUValue).arg(m_fMemeryValue);
	m_plblCPUAndMemery->setText(m_strCPUAndMemery);

	QDateTime dataTime;
	QString strDateTime = dataTime.currentDateTime().toString(QString("yyyy.MM.dd  hh:mm:ss"));
	m_plblCurrentTime->setText(strDateTime);
}

//1207重新排版
void HDCDomeVideoContainer::sltSetScreenVideo(int nScreen)
{
   pauseVideos(m_pslAddVideoPage->currentIndex());

	m_nOldVideoCount = getCurrentVideoCount();
	int nStackedLayoutWidget = m_pslAddVideoPage->count();
	HDCDomeVideoGroup *t_pwndVideoGroup;
	if ( (m_nOldVideoCount != nScreen) )
	{
		//判断是否是多页多屏变单屏显示判断
		if (nStackedLayoutWidget > 1)
		{
			m_bIsPageChanged = true;
		}

		if ((m_pslAddVideoPage->count()  == 1) && (m_bIsPageChanged == false))
		{
			m_pwndPopScreenSelect->hide();
			sltSetVideoCount(nScreen);
		}
		else
		{
			m_pwndPopScreenSelect->hide();

			QString strDevicedId;
			QList<HDCDomeVideoPanel *> lstAllVideoPanels;
			QList<HDCDomeVideoPanel *> lstOpenVideoPanels;
			//QList<HDCDomeVideoPanel *> lstNullVideoPanels;
			for (int nPage = 0; nPage < nStackedLayoutWidget; nPage++)
			{
				HDCDomeVideoGroup * t_pwndGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(nPage));
				QList<HDCDomeVideoPanel *> lstVideoPanels = t_pwndGroup->getAllVideoPanels();
				for (int i = 0; i < lstVideoPanels.count(); i++)
				{
					if (!lstAllVideoPanels.contains(lstVideoPanels.at(i)))
					{
						//lstVideoPanels.at(i)->setParent(NULL);
						lstVideoPanels.at(i)->hide();
						lstAllVideoPanels.push_back(lstVideoPanels.at(i));
						strDevicedId = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstVideoPanels.at(i));
						if (strDevicedId != "default")
						{
							lstOpenVideoPanels.push_back(lstVideoPanels.at(i));
						}
						else
						{
							//lstNullVideoPanels.push_back(lstAllVideoPanels.at(i));
						}
					}
				}
			}
			
			//重新计算页数
			int nRestPanel= lstOpenVideoPanels.count() % nScreen;
			int nNewPages;
			if (nRestPanel >= 0)
			{
				nNewPages = lstOpenVideoPanels.count() / nScreen + 1;
			}
			else
			{
				nNewPages = lstOpenVideoPanels.count() /nScreen;
			}

			clearXmlFileVideoPanelConfig();

			//1221处理屏数：少—>多,页码：多—>少；改造原来的页码，删除多余的页码							
			if (nScreen > m_nOldVideoCount)
			{
				int nPageIndex;
				for (int npage = 0; npage < (m_pslAddVideoPage->count()); npage++)
				{
					m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(npage));
					if (npage < nNewPages)
					{
						//改造原来的页面						
						m_pwndVideoGroup->setCurrentVideoCount(nScreen);
						m_pwndVideoGroup->clearListVidePanels();
						for (int npanelIndex = 0; npanelIndex< nScreen; npanelIndex++)
						{
							nPageIndex = npage * nScreen + npanelIndex;
							if (nPageIndex < lstOpenVideoPanels.count())
							{
								lstOpenVideoPanels.at(nPageIndex)->setParent(m_pwndVideoGroup);
								m_pwndVideoGroup->setVideoPanel(lstOpenVideoPanels.at(nPageIndex));
								if (nPageIndex != 0)
								{
									videoPanelConnections(lstOpenVideoPanels.at(nPageIndex));
								}
								saveChangedVideoCountConfigInfo(lstOpenVideoPanels.at(nPageIndex),npanelIndex,npage,nNewPages);
							}
						} 

						//处理最后一页的显示
						if (npage == (nNewPages -1))
						{
							//剩余空绘制窗口
							int nrestpanel = lstAllVideoPanels.count() - lstOpenVideoPanels.count();
							//该页需充满时需要的绘制窗口
							int naddpanel = nScreen - nRestPanel;

							//剩余空绘制窗口足够填充该页面，则充满该页面，并隐藏或删除多余的空绘制窗口，否则新建绘制窗口补足该页面
							if (nrestpanel > naddpanel)
							{
								int npanel = 0;
								for (int i = 0; i < lstAllVideoPanels.count(); i++)
								{
									strDevicedId = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstAllVideoPanels.at(i));
									if (strDevicedId == "default")
									{											
										if (npanel < naddpanel)
										{
											npanel++;
											lstAllVideoPanels.at(i)->setParent(m_pwndVideoGroup);
											m_pwndVideoGroup->setVideoPanel(lstAllVideoPanels.at(i));
											videoPanelConnections(lstAllVideoPanels.at(i));
											int npos = npanel + nRestPanel;
											saveChangedVideoCountConfigInfo(lstAllVideoPanels.at(i),npos,npage,nNewPages);
											continue;
										}
										else
										{
											//是否需要隐藏处理未显示的绘制窗口
											//lstAllVideoPanels.at(i)->hide();
										}
									}
								}									
							}
							else
							{
								int npanel = 0;
								for (int i = 0; i < lstAllVideoPanels.count(); i++)
								{
									strDevicedId = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstAllVideoPanels.at(i));
									if (strDevicedId == "default")
									{			
										lstAllVideoPanels.at(i)->setParent(m_pwndVideoGroup);
										m_pwndVideoGroup->setVideoPanel(lstAllVideoPanels.at(i));
										videoPanelConnections(lstAllVideoPanels.at(i));
										int npos = nRestPanel + npanel;
										saveChangedVideoCountConfigInfo(lstAllVideoPanels.at(i),npos,npage,nNewPages);
										npanel++;
									}
								}
								//增加新建的绘制窗口
								for (int i = 0; i < (naddpanel - npanel); i++)
								{
									newVideoPanel(m_pwndVideoGroup);
									QList<HDCDomeVideoPanel*> lstnewpanel = m_pwndVideoGroup->getAllVideoPanels();
									int npos = npanel + nRestPanel + i;
									saveChangedVideoCountConfigInfo(lstnewpanel.at(npos),npos,npage,nNewPages);
								}	
							}
						}
						//重新布局改造后的页面
						m_pwndVideoGroup->initGridInfo(nScreen);
						m_pwndVideoGroup->adjustSize();
					    connect(m_pwndVideoGroup,SIGNAL(sigsetVideoCount(int)),this,SLOT(sltSetVideoCount(int)));
					}
					else
					{
						//删除多余的页面	
						m_pslAddVideoPage->removeWidget(m_pwndVideoGroup);
						delete m_pwndVideoGroup;
						m_pwndVideoGroup = NULL;	
						npage--;
					}					
				}				
			}
			 //1222处理屏数：多—>少，页码：少->多；改造原来的页码，新建补充的页码
			else
			{
				int nPageIndex;
				for (int npage = 0; npage < nNewPages; npage++)
				{
					if (npage < nStackedLayoutWidget)
					{
						//改造原来页面
						m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(npage));
						m_pwndVideoGroup->setCurrentVideoCount(nScreen);
						m_pwndVideoGroup->clearListVidePanels();
						for (int npanelIndex = 0; npanelIndex< nScreen; npanelIndex++)
						{
							nPageIndex = npage * nScreen + npanelIndex;
							if (nPageIndex < lstOpenVideoPanels.count())
							{
								lstOpenVideoPanels.at(nPageIndex)->setParent(m_pwndVideoGroup);
								m_pwndVideoGroup->setVideoPanel(lstOpenVideoPanels.at(nPageIndex));
								if (nPageIndex != 0)
								{
									videoPanelConnections(lstOpenVideoPanels.at(nPageIndex));
								}
								saveChangedVideoCountConfigInfo(lstOpenVideoPanels.at(npanelIndex),npanelIndex,npage,nNewPages);
							}
						}

						//处理最后一页的显示（不需要新建绘制窗口，原来空的绘制窗口够用）
						if (npage == (nNewPages -1))
						{
							//该页需充满时需要的绘制窗口
							int naddpanel = nScreen - nRestPanel;
							int npanel = 0;
							for (int i = 0; i < lstAllVideoPanels.count(); i++)
							{
								strDevicedId = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstAllVideoPanels.at(i));
								if (strDevicedId == "default")
								{											
									if (npanel < naddpanel)
									{
										npanel++;
										lstAllVideoPanels.at(i)->setParent(m_pwndVideoGroup);
										m_pwndVideoGroup->setVideoPanel(lstAllVideoPanels.at(i));
										videoPanelConnections(lstAllVideoPanels.at(i));
										int nPos = npanel + nRestPanel;
										saveChangedVideoCountConfigInfo(lstAllVideoPanels.at(i),nPos,npage,nNewPages);
										continue;
									}
									else
									{
										//是否需要隐藏处理未显示的绘制窗口
										//lstAllVideoPanels.at(i)->hide();
									}
								}
							}									
						}
					}
					else
					{
						//增加新建页面
						m_pwndVideoGroup = new HDCDomeVideoGroup;
						m_pslAddVideoPage->addWidget(m_pwndVideoGroup);
						m_pwndVideoGroup->setCurrentVideoCount(nScreen);
						m_pwndVideoGroup->clearListVidePanels();
						for (int npanelIndex = 0; npanelIndex< nScreen; npanelIndex++)
						{
							nPageIndex = npage * nScreen + npanelIndex;
							if (nPageIndex < lstOpenVideoPanels.count())
							{
								lstOpenVideoPanels.at(nPageIndex)->setParent(m_pwndVideoGroup);
								m_pwndVideoGroup->setVideoPanel(lstOpenVideoPanels.at(nPageIndex));
								videoPanelConnections(lstOpenVideoPanels.at(nPageIndex));
								saveChangedVideoCountConfigInfo(lstOpenVideoPanels.at(nPageIndex),npanelIndex,npage,nNewPages);
							}
						}
						//处理最后一页的显示
						if (npage == (nNewPages -1))
						{
							//剩余空绘制窗口
							int nrestpanel = lstAllVideoPanels.count() - lstOpenVideoPanels.count();
							//该页需充满时需要的绘制窗口
							int naddpanel = nScreen - nRestPanel;

							//剩余空绘制窗口足够填充该页面，则充满该页面，并隐藏或删除多余的空绘制窗口，否则新建绘制窗口补足该页面
							if (nrestpanel > naddpanel)
							{
								int npanel = 0;
								for (int i = 0; i < lstAllVideoPanels.count(); i++)
								{
									strDevicedId = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstAllVideoPanels.at(i));
									if (strDevicedId == "default")
									{											
										if (npanel < naddpanel)
										{
											npanel++;
											lstAllVideoPanels.at(i)->setParent(m_pwndVideoGroup);
											m_pwndVideoGroup->setVideoPanel(lstAllVideoPanels.at(i));
											videoPanelConnections(lstAllVideoPanels.at(i));
											int npos = npanel + nRestPanel;
											saveChangedVideoCountConfigInfo(lstAllVideoPanels.at(i),npos,npage,nNewPages);
											continue;
										}
										else
										{
											//是否需要隐藏处理未显示的绘制窗口
											//lstAllVideoPanels.at(i)->hide();
										}
									}
								}									
							}
							else
							{
								int npanel = 0;
								for (int i = 0; i < lstAllVideoPanels.count(); i++)
								{
									strDevicedId = m_pwndVideoGroup->getDeviceIDFromVideoPanel(lstAllVideoPanels.at(i));
									if (strDevicedId == "default")
									{							
										lstAllVideoPanels.at(i)->setParent(m_pwndVideoGroup);
										m_pwndVideoGroup->setVideoPanel(lstAllVideoPanels.at(i));
										videoPanelConnections(lstAllVideoPanels.at(i));
										int npos = npanel + nRestPanel;
										saveChangedVideoCountConfigInfo(lstAllVideoPanels.at(i),npos,npage,nNewPages);
										npanel++;
									}
								}
								//增加新建的绘制窗口
								for (int i = 0; i < (naddpanel - npanel); i++)
								{
									newVideoPanel(m_pwndVideoGroup);
									QList<HDCDomeVideoPanel*> lstnewpanel = m_pwndVideoGroup->getAllVideoPanels();
									int npos = npanel + i + nRestPanel;
									saveChangedVideoCountConfigInfo(lstnewpanel.at(npos),npos,npage,nNewPages);
								}	
							}
						}
					}

					//重新布局改造后的页面
					m_pwndVideoGroup->initGridInfo(nScreen);
					m_pwndVideoGroup->adjustSize();

					connect(m_pwndVideoGroup,SIGNAL(sigsetVideoCount(int)),this,SLOT(sltSetVideoCount(int)));
				}
			}
			
			recalculateStackedLayoutWidgets();	 
		}

		m_nOldVideoCount = nScreen;
	}
	else
	{
		  m_pwndPopScreenSelect->hide();
		  sltSetVideoCount(nScreen);
	}

	m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(0));
	m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);
	m_pwndVideoGroup->setPanelChecked(0, true);
	continueVideos(0);
}

//void HDCDomeVideoContainer::sltScreenSelectBtnClicked()
//{
//    QObject *obj_sender = QObject::sender();
//    QPushButton *t_ppbScreenSelect = dynamic_cast<QPushButton*>(obj_sender);
//    if(t_ppbScreenSelect)
//    {
//        int nID = m_pbgPopScreenSelect->id(t_ppbScreenSelect);
//        m_pwndVideoGroup->setVideoCount(nID);
//    }
//}

void HDCDomeVideoContainer::sltShowPopScreenSelect()
{
   m_pwndPopScreenSelect->setParent(NULL);
   int nShowX = 0;
   int nShowY = 0;
   QObject *t_objSender = QObject::sender();
   QPushButton *t_pSplitScreen = dynamic_cast<QPushButton*>(t_objSender);
   if(t_pSplitScreen)
   {
       QPoint pointGlobal;
       pointGlobal = t_pSplitScreen->mapToGlobal(QPoint(0,0));
        nShowX = pointGlobal.x();
        nShowY = pointGlobal.y() + t_pSplitScreen->height() + 5;
   }
   m_pwndPopScreenSelect->move(nShowX,nShowY);
   m_pwndPopScreenSelect->show();
}

void HDCDomeVideoContainer::sltShowStateChanged()
{
	if(m_bShowFullScreen)
	{
		m_ppbShowStateChange->setObjectName("dc_btn_showFullScrren");
		m_ppbShowStateChange->setToolTip(QString::fromLocal8Bit("全屏显示"));
	}
	else
	{
		m_ppbShowStateChange->setObjectName("dc_btn_showNormalScrren");
		m_ppbShowStateChange->setToolTip(QString::fromLocal8Bit("非全屏显示"));
	}
	m_bShowFullScreen = !m_bShowFullScreen;
	emit sigShowFullScreen(m_bShowFullScreen);
	QApplication::sendEvent(m_ppbShowStateChange,&QEvent(QEvent::Leave));
}

void HDCDomeVideoContainer::sltTurnPreviousPage()
{
	int icurrentPage = m_pslAddVideoPage->currentIndex();
	if (icurrentPage != 0)
	{		
		//关闭上当前页的视频
		pauseVideos(icurrentPage);

		//打开前一页的视频
		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(icurrentPage -1));
		m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);
		continueVideos(icurrentPage -1);

		//20161212解决窗口绘制的设备媒体流无法关闭问题
		connect(m_pwndVideoGroup,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)),this,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)));
		
		stackedLayoutPageChangedRestartTimer();
		calculateStackedLayoutWidgets();
	}	
	else
	{
		return;
	}
}

void HDCDomeVideoContainer::sltTurnPage1()
{
	//停止当前页面上打开设备的媒体流
	int nCurrentIndex = m_pslAddVideoPage->currentIndex();
	pauseVideos(nCurrentIndex);

	//显示当前窗口，继续播放当前页面打开设备的媒体流
	int iPage = m_ppbPage1->text().toInt();
	m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(iPage-1));
	m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);
    continueVideos(iPage - 1);

	stackedLayoutPageChangedRestartTimer();
	calculateStackedLayoutWidgets();
}

void HDCDomeVideoContainer::sltTurnPage2()
{
	//停止当前页面打开设备的媒体流
	int nCurrentIndex = m_pslAddVideoPage->currentIndex();
	pauseVideos(nCurrentIndex);
	

	//显示当前窗口，继续播放当前页面打开设备的媒体流
	int iPage = m_ppbPage2->text().toInt();
	m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(iPage-1));
	m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);
	continueVideos(iPage - 1);

	stackedLayoutPageChangedRestartTimer();
	calculateStackedLayoutWidgets();
}

void HDCDomeVideoContainer::sltTurnPage3()
{
	//停止当前页面打开设备的媒体流
	int nCurrentIndex = m_pslAddVideoPage->currentIndex();
	pauseVideos(nCurrentIndex);

	//显示当前窗口，继续播放当前页面打开设备的媒体流
	int iPage = m_ppbPage3->text().toInt();
	m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(iPage-1));
	m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);
	continueVideos(iPage - 1);

	stackedLayoutPageChangedRestartTimer();
	calculateStackedLayoutWidgets();
}

void HDCDomeVideoContainer::sltTurnNextPage()
{
	int icurrentPage = m_pslAddVideoPage->currentIndex();
	m_iPageCount = m_pslAddVideoPage->count();
	if((icurrentPage + 1) < m_iPageCount)
	{
		//停止当前页打开设备的媒体流
		pauseVideos(icurrentPage);

		//打开下页设备,如果有打开媒体流，继续打开
		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(icurrentPage +1));
		m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);
		continueVideos(icurrentPage + 1);
		connect(m_pwndVideoGroup,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)),this,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)));

		stackedLayoutPageChangedRestartTimer();
		calculateStackedLayoutWidgets();
	}
	else
	{
		return;
	}	
}

void HDCDomeVideoContainer::sltJumpToPage()
{
	int ijumpPage = m_pleJumpPage->text().toInt();
	m_iPageCount = m_pslAddVideoPage->count();
	if( ijumpPage <= m_iPageCount && ijumpPage > 0 )
	{
		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(ijumpPage));
		m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);

		if (m_iPageCount >= 3)
		{
			if (ijumpPage == 1 )
			{
				m_ppbPage1->setText(QString("%1").arg(ijumpPage));
				m_ppbPage2->setText(QString("%1").arg(ijumpPage+1));
				m_ppbPage3->setText(QString("%1").arg(ijumpPage+2));
			}
			else if (ijumpPage == m_iPageCount )
			{
				m_ppbPage1->setText(QString("%1").arg(ijumpPage-2));
				m_ppbPage2->setText(QString("%1").arg(ijumpPage-1));
				m_ppbPage3->setText(QString("%1").arg(ijumpPage));
			}
			else
			{
				m_ppbPage1->setText(QString("%1").arg(ijumpPage-1));
				m_ppbPage2->setText(QString("%1").arg(ijumpPage));
				m_ppbPage3->setText(QString("%1").arg(ijumpPage+1));
			}
		}
		else
		{
			if (ijumpPage == 1 )
			{
				m_ppbPage1->setText(QString("%1").arg(ijumpPage));
				m_ppbPage2->setText(QString("%1").arg(ijumpPage+1));
			}
			else if (ijumpPage == m_iPageCount )
			{
				m_ppbPage1->setText(QString("%1").arg(ijumpPage-1));
				m_ppbPage2->setText(QString("%1").arg(ijumpPage));
			}
		}
		stackedLayoutPageChangedRestartTimer();
	}
	else 
	{
		return;
	}
	
}

void HDCDomeVideoContainer::sltTourPlayStart()
{
	m_ppbTourOpen->setStyleSheet("background-color:#555555");
	m_ppbTourClose->setStyleSheet("background-color:#8A8A8A");
	//获得轮巡参数,分钟计时,合并后调用接口
	QString strTime = "10"; 
	connect(m_pTourPlayTimer,SIGNAL(timeout()),this,SLOT(sltTourPlayTimeOut()));
	m_pTourPlayTimer->start(20000);
}

void HDCDomeVideoContainer::sltTourPlayTimeOut()
{
	int nCurrentPage = m_pslAddVideoPage->currentIndex();

	//停止当前页打开设备的媒体流
	pauseVideos(nCurrentPage);
	if (nCurrentPage != (m_pslAddVideoPage->count() - 1))
	{
		//打开下页设备,如果有打开媒体流，继续打开
		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup *>(m_pslAddVideoPage->widget(nCurrentPage + 1));
		m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);
		continueVideos(nCurrentPage + 1);
	}
	else
	{
		m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup*>(m_pslAddVideoPage->widget(0));
		m_pslAddVideoPage->setCurrentWidget(m_pwndVideoGroup);
		continueVideos(0);
	}

	connect(m_pwndVideoGroup,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)),this,SIGNAL(sigCloseVideo(HDCDomeVideoPanel*)));
	calculateStackedLayoutWidgets();

	//告警信息处理
}

void HDCDomeVideoContainer::stackedLayoutPageChangedRestartTimer()
{
	//如果计时器计时没有用完，当前页码发生变化，从当前页码开始重新开始计时 
	m_pTourPlayTimer->stop();
	//m_pTourPlayTimer->setInterval(0);
	//connect(m_pTourPlayTimer,SIGNAL(timeout()),this,SLOT(sltTourPlayTimeOut()));
	m_pTourPlayTimer->start(); 
}

void HDCDomeVideoContainer::sltTourPlayClose()
{
	m_ppbTourClose->setStyleSheet("background-color:#555555");
	m_ppbTourOpen->setStyleSheet("background-color:#8A8A8A");
	m_pTourPlayTimer->stop();
	m_pwndVideoGroup = dynamic_cast<HDCDomeVideoGroup*>(m_pslAddVideoPage->currentWidget());
}
